// import 'babel-polyfill';
import '@babel/polyfill';

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import Order from './components/Order';

import ServicePlugin from './service/service.plugin';
import CookieNames from './constant/CookieName';

import ElementUI from 'element-ui';

// import './../node_modules/bootstrap/dist/css/bootstrap.css';

Vue.config.productionTip = false

Vue.use(ElementUI, {
  size: 'mini'
});
Vue.use(ServicePlugin, {});

router.beforeEach((to, from, next)=>{
    let login = to.name === 'login',
        notFound = to.name === 'NotFound',
        hasMenu = store.state.menuList.length === 0;
    // console.info(to);
    // 校验没有登录和notFound的情况
    if( login || notFound ) return next();
    
    // 校验没有左侧菜单，要全部跳转到登录
    // if( hasMenu && (!login || !notFound) ) return router.push({name: 'login'});
    let $cookie = Vue.prototype.$cookie;
    let token = $cookie.get(CookieNames.TOKEN);
    if( !token ) {
        Object.keys(CookieNames).forEach(key=>{
            $cookie.set(CookieNames[key], '', -1);
        });
        return router.replace({name: 'login'});
    }
    return next();
});

new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    // router.addRoutes([
    //       {
    //           path: '/order',
    //           name: 'orderName',
    //           component: (resolve)=>{
    //               setTimeout(()=>{
    //                 require(['./components/Order'], resolve);
    //               }, 5000);
    //           }
    //       }
    //   ]);
    //   this.$nextTick(()=>{
    //     this.$router.push({path: 'order'});
    //   });
  },
}).$mount('#app')
